{% extends 'rating/base.html' %}
{% block title %}评分项管理{% endblock %}
{% block content %}
    <section class="content">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">评分项预览</h3>

                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-danger" onclick="deleteSelectRatingItem();"><i
                            class="fa fa-trash">删除评分项</i>
                    </button>
                    <button type="button" class="btn btn-success" onclick="createRatingItem()"><i class="fa fa-plus">添加评分项</i>
                    </button>
                </div>
            </div>
            <div class="box-body">
                <form id="delete_form" action="{% url 'rating:delete_item' %}" method="post">
                    {% csrf_token %}
                    <table class="table dataTable">
                        <thead>
                        <tr>
                            <th style="width: 40px"><input id="select_all_checkbox" type="checkbox"></th>
                            <th>#</th>
                            <th>评分项名称</th>
                            <th>级别显示</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for item in item_list %}
                            {% with a_item=item|first %}
                                <tr class="pointer_tr">
                                    <td><input class="choose_box" type="checkbox" name="check_{{ a_item.item_id }}">
                                    </td>
                                    <td class="pointer_td"
                                        onclick="clickRatingItem({{ a_item.item_id }})">{{ a_item.item_id }}</td>
                                    <td class="pointer_td"
                                        onclick="clickRatingItem({{ a_item.item_id }})">{{ a_item.title }}</td>
                                    <td class="pointer_td" onclick="clickRatingItem({{ a_item.item_id }})">
                                        {% with levels=item|last %}
                                            {% for l in levels %}
                                                {{ l.title }}:{{ l.score }}分;
                                            {% endfor %}
                                        {% endwith %}
                                    </td>
                                    <td class="pointer_td" onclick="clickRatingItem({{ a_item.item_id }})">
                                        {% if a_item.description == None %}
                                        {% else %}
                                            {{ a_item.description }}
                                        {% endif %}</td>
                                </tr>
                            {% endwith %}

                        {% endfor %}
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </section>
{% endblock %}
{% block script %}
    <script>
        function createRatingItem() {
            var new_url = "{% url 'rating:create_item' %}?type=create";
            generateAutoReloadWindow(new_url, 'height=600, width=600, top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=yes,location=no, status=no');
        }

        function deleteSelectRatingItem() {
            $('#delete_form').submit();
        }

        function clickRatingItem(item_id) {

        }
    </script>
{% endblock %}